<template>
  <el-dialog
    class="off_dialog"
    width="500px"
    title="下架"
    :visible.sync="dialogVisible"
    :close-on-click-modal="false"
  >
    <p class="text-center tip">您确定要下架处理该商品吗？</p>
    <el-form
      class="ruleForm"
      :model="form"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
    >
      <el-form-item
        label="原因"
        prop="reason"
      >
        <el-select
          v-model="form.reason"
          placeholder="请选择"
        >
          <el-option
            label="图片不符合规范"
            value="图片不符合规范"
          ></el-option>
          <el-option
            label="商品内容有敏感字符"
            value="商品内容有敏感字符"
          ></el-option>
          <el-option
            label="其他原因"
            :value="3"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item
        v-show="form.reason==3"
        label="其他原因"
      >
        <el-input
          type="textarea"
          :rows="4"
          placeholder="请输入备注原因信息！例如：图片不符合规范"
          v-model="form.other"
        >
        </el-input>
      </el-form-item>
    </el-form>
    <div
      slot="footer"
      class="dialog-footer"
    >
      <el-button
        size="small"
        @click="dialogVisible = false"
      >取 消</el-button>
      <el-button
        size="small"
        type="primary"
        @click="submit"
      >确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { itemDownShelf } from "@/api/audit";
export default {
  data() {
    return {
      form: {
        reason: "",
        other: ""
      },
      rules: {
        reason: [
          { required: true, message: '请选择原因', trigger: 'change' }
        ]
      },
      dialogVisible: false,
      goodsId: null
    }
  },
  methods: {
    submit() {
      this.$refs['ruleForm'].validate((valid) => {
        if (valid) {
          const params = {
            goods_id: this.goodsId,
            check_reason: ''
          }
          if (this.form.reason == 3) {
            params.check_reason = this.form.other;
          } else {
            params.check_reason = this.form.reason;
          }
          itemDownShelf(params).then(res => {
            this.dialogVisible = false;
            this.$emit('getList', true);
          })
        } else {
          this.$message({
            message: "请检查表单错误",
            type: "error"
          });
          return false;
        }
      });
    }
  },
  watch: {
    dialogVisible(val) {
      if (val) {
        this.$nextTick(() => {
          this.$refs['ruleForm'].resetFields();
        })
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.tip {
  line-height: 35px;
  margin-bottom: 10px;
}
</style>
